//
//  RealHouseListViewController.m
//  Utils
//
//  Created by enghou on 2018/4/28.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "RealHouseListViewController.h"
#import "HouseItemModel.h"
#import "RealHouseSearchViewController.h"
#import "LocalPersistent.h"
#import "RealHouseDetailViewController.h"
#import "HouseDetailContainerViewController.h"
@interface RealHouseListViewController ()

@end

@implementation RealHouseListViewController

-(void)searchAction{
    RealHouseSearchViewController *search = (RealHouseSearchViewController *)[VCLoader vcWithName:@"RealHouseSearchViewController"];
    search.title = @"房屋查询";
    search.theDelete = self;
    [self push:search];
}

-(NSString *)orgId{
    return [[LocalPersistent sharedInstance]contentForKey:@"orgId"];
}

-(void)addAction{
    RealHouseDetailViewController *real = [[RealHouseDetailViewController alloc]init];
    real.title = @"新增";
    [self push:real];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(beginRefresh) name:@"refresh_real_house" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"];
        cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"999999"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    HouseItemModel *model = [self.source objectAtIndex:indexPath.row];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:@"icon_enterprise"]];
    cell.textLabel.text = model.title;
    cell.detailTextLabel.text = model.detail;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    HouseDetailContainerViewController *container = [[HouseDetailContainerViewController alloc]init];
    container.title = @"实有房屋详情";
    HouseItemModel *model = [self.source objectAtIndex:indexPath.row];
    container.ids = model.ids;
    [self push:container];
}

-(void)pushWithId:(NSString *)ids{
    [self alertSome:@"该功能暂未开放"];
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
